<?PHP
		function textile($source){
			$search = array(
				"/^(\#\s.*?)\n([^\#])/sm", //ORDER LIST
				"/^(\*\s.*?)\n([^\*])/sm", //UNORDER LIST
				"/\n(?:\*|\#)\s(.*)\r/m",
				"/_(.*?)_/", // EMPHASIS
				"/\*(.*?)\*/", // STRONG
				"/\?\?(.*?)\?\?/", // CITE
				"/^h([1-6])\.(.*?)\r$/m",
				"/^bq\.(.*?)\r$/m", // BLOCKQUOTE
				"/(\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)/i", //MAILS
				"/\"(.*?)\"\:([^\s]*)/",
				"/\!(.*?)\!/",
				"/^\s*line\.\s*$/m",
				"/^\s*$/m",
				"/\r\n/"
				);
			$replace = array(
				//"<font color=\"#FF0000\">\n$1</font>\n$2",
				"<ol>\n$1</ol>\n$2",
				"<ul>\n$1</ul>\n$2",
				"<li>$1</li>",
				"<em>$1</em>",
				"<strong>$1</strong>",
				"<cite>$1</cite>",
				"<h$1>$2</h$1>",
				"<blockquote>$1</blockquote>",
				"<a href=\"mailto:$1\">$1</a>",
				"<a href=\"$2\">$1</a>",
				"<img src=\"$1\" />",
				"<hr />",
				"</p><p>",
				"<br />\r\n"
				);
			$result = preg_replace($search,$replace,$source);
			return "<p>".$result."</p>";
		}
		function removeTextile($source){
			$search = array(
				"/^(\#\s.*?)\n([^\#])/sm", //ORDER LIST
				"/^(\*\s.*?)\n([^\*])/sm", //UNORDER LIST
				"/\n(?:\*|\#)\s(.*)\r/m",
				"/_(.*?)_/", // EMPHASIS
				"/\*(.*?)\*/", // STRONG
				"/\?\?(.*?)\?\?/", // CITE
				"/^h([1-6])\.(.*?)\r$/m",
				"/^bq\.(.*?)\r$/m", // BLOCKQUOTE
				"/(\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)/i", //MAILS
				"/\"(.*?)\"\:([^\s]*)/",
				"/\!(.*?)\!/",
				"/^\s*line\.\s*$/m",
				"/^\s*$/m",
				"/\r\n/"
				);
			$replace = array(
				//"<font color=\"#FF0000\">\n$1</font>\n$2",
				"\n$1\n$2",
				"\n$1\n$2",
				"$1\r\n",
				"$1",
				"$1",
				"$1",
				"$2\r\n",
				"$1",
				"$1",
				"<a href=\"$2\">$1</a>",
				"",
				"",
				"",
				"<br />\r\n"
				);
			$result = preg_replace($search,$replace,$source);
			return $result;
		}
		function resume($text, $length = 200, $use_textile = false){
			$source = (strlen($text)<$length) ? $text : substr($text, 0, strrpos (substr($text, 0, $length), " "))." &#8230;";
			if($use_textile){
				$result = textile($source);
			}else{
				$result = removeTextile($source);
			}
			return $result;
		}
?>